import { BeanScope } from './BeanScope';
import { ClassType } from '../type';
import { DependencyLike } from './DependencyLike';


/**
 * Bean定义
 * @author Zhang
 * @date 2019/3/19 9:26
 */
export class BeanDefinition {
  /**
   * Bean名称
   */
  name: string;
  /**
   * Bean类名
   */
  beanClass: ClassType<any>;
  /**
   * Bean scope
   */
  scope: BeanScope = BeanScope.SINGLETON;
  /**
   * 依赖的其他bean
   */
  dependsOn: DependencyLike[];
  /**
   * 是否主候选
   */
  primary: boolean;

  /**
   * Bean实例，由工厂类创建并赋值
   */
  instance: object | (() => object);

  /**
   * 是否单例
   */
  isSingleton(): boolean {
    return this.scope === BeanScope.SINGLETON;
  }

  /**
   * 是否原型
   */
  isPrototype(): boolean {
    return this.scope === BeanScope.PROTOTYPE;
  }
}
